home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: doubly dimensioned arrays
- Date: 20 Jan 1996 00:49:04 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4dpe60$l6k@colossus.holonet.net>
- References: <4dlje4$bnf@News1.mcs.net>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- stevecoh.mcs.com wrote:
- : how must the variable p be declared so that the following code
- : int m,n; ... p=new int[m][n]; ... p[m][n]
- : gives the expected result, that is the int at the nth column of the mth
- : row?
-
- To use the above, at least n (and optionally m) must be const, with a
- value known at compile time. You can then have the following:
- const int n = 42; // or whatever
- int m; // init as you wish
- ...
- int (*p)[n] = new int[m][n]; // the answer to your question
-
- but, BTW, don't try to access p[m][n]. Remember, the last element
- is p[m-1][n-1].
-
- If n cannot be a const, you need to use other techniques. Best
- is to forget about arrays and use a Vector class.
- --
- Russell Blackadar, russell@mdli.com
-